/**
 * Ant Design Pro v4 use `@ant-design/pro-layout` to handle Layout.
 * You can view component api by:
 * https://github.com/ant-design/ant-design-pro-layout
 */
import React from 'react';
import { connect } from 'dva';
import router from 'umi/router';
import { setToken } from '@/utils/authority';
import { getPageQuery } from '@/utils/utils';
import Loading from '@/components/PageLoading';

const GetToken = () => {
  const params = getPageQuery();
  if (params && params.token) {
    setToken(params.token);
    if (params.from) {
      location.href = params.from;
    } else {
      location.href = '/';
    }
    // router.replace('/');
    // if (dispatch) {
    //   dispatch({
    //     type: 'token/save',
    //     payload: {
    //       token: params.token,
    //       callback: () => {
    //         const querystring = getPageQuery();
    //         let { from } = querystring;
    //         if (from && from.indexOf('#') > 0) {
    //           // eslint-disable-next-line prefer-destructuring
    //           from = from.split('#')[1];
    //         } else {
    //           from = '/';
    //         }
    //       },
    //     },
    //   });
    // }
  }

  return <Loading></Loading>;
};

export default connect()(GetToken);
